import Vue from 'vue'
import Router from 'vue-router'
import global from '@/common/global.js'
import index from '@/views/index'
import chengben from '@/views/chengben'
import ziyuan from '@/views/ziyuan'
import pay from '@/components/pay'
import advice from '@/components/advice'
import fuzai from '@/components/fuzai'

Vue.use(Router)

export default new Router({
  mode: 'history',
  routes: [
    {
      path: '/',
      name: 'index',
      component: index,
    },
    {
      path: `/${global.config.chengben}`,
      name: `${global.config.chengben}`,
      component: chengben,
      redirect: `${global.config.chengben}/${global.config.pay}`,
      children: [
        {
          path: `${global.config.pay}`,
          name: `${global.config.pay}`,
          component: pay,
        },
        {
          path: `${global.config.advice}`,
          name: `${global.config.advice}`,
          component: advice,
        },
      ],
    },
    {
      path: `/${global.config.ziyuan}`,
      name: `${global.config.ziyuan}`,
      component: ziyuan,
    },
    {
      path: `/${global.config.fuzai}`,
      name: `${global.config.fuzai}`,
      component: fuzai,
    },
    {
      redirect: '/',
      path: `/${global.config.total}`,
      name: `${global.config.total}`,
      component: index,
    },
  ],
})

const originalPush = Router.prototype.push
//修改原型对象中的push方法
Router.prototype.push = function push(location) {
  return originalPush.call(this, location).catch((err) => err)
}
